package com.yixin.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.springframework.stereotype.Component;
import org.aspectj.lang.annotation.Aspect;

@Slf4j
@Aspect
@Component
public class RecordTimeAspect {
    @Around("execution(* com.yixin.service.impl.*.*(..))")
    public Object recordTime(ProceedingJoinPoint pjp) throws Throwable {
        // 1. 记录方法运行的开始时间
        long begin = System.currentTimeMillis();

        // 2. 执行目标方法
        Object result = pjp.proceed();

        // 3. 获取方法运行的返回值
        long end = System.currentTimeMillis();
        log.info("方法{}运行耗时：{}ms", pjp.getSignature(), (end - begin));
        return result;

    }
}
